package com.linwen.excise.od.C;

import java.util.*;

/**
 * @ClassName _部门人力分配
 * @Description TODO
 * @Author zero
 * @DATE 2024/4/4 7:31 PM
 * @Version 1.0
 */
public class _部门人力分配 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int m = in.nextInt();
        in.nextLine();
        String input_str = in.nextLine();
        String[] tmp2 = input_str.split(" ");
        int[] nums = new int[tmp2.length];
        for (int i = 0; i < tmp2.length; i++) {
            nums[i] = Integer.parseInt(tmp2[i]);
        }
        Arrays.sort(nums);
        // 最小是最后一个月的工作人力，最大是两个月的人力之和
        int low = nums[nums.length-1];
        int high = nums[nums.length-1] + nums[nums.length-2];
        while (low<high) {
            int k = low+(high-low)/2;
            if (cal(k, nums, nums.length) > m) {
                low = k + 1;
            } else {
                high = k;
            }

        }
        System.out.println(low);
    }

    public static int cal(int k, int[] nums, int length) {
        int low = 0;
        int high = length - 1;
        int months = 0;
        while (true) {
            if(low > high){
                break;
            } else {
                if (nums[low] + nums[high] > k) {
                    high -= 1;
                } else {
                    low += 1;
                    high -= 1;
                }
                months+=1;
            }
        }
        return months;
    }
}
